<?php
/**
 * Ratings.php
 *
 * PHP version 5
 *
 * LICENSE: This source file is subject to version 2.0 of the Apache license
 * that is available through the world-wide-web at the following URI:
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * @category Controller
 * @package  Controller
 * @author   David Bradley <bradld2@rpi.edu>
 * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
 * @link     http://http://code.google.com/p/tri-chi/
 */
 
 /**
 * Ratings
 *
 * The model that manages Ratings
 * 
 * The followings are the available columns in table 'ratings':
 * 
 * @property string $id
 * @property string $pnm_id
 * @property string $member_username
 * @property string $rating
 * @property string $comment
 *
 * The followings are the available model relations:
 * @property Pnm $pnm
 * @property Users $memberUsername
 *
 * @category Controller
 * @package  Controller
 * @author   David Bradley <bradld2@rpi.edu>
 * @license  http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
 * @link     http://http://code.google.com/p/tri-chi/
 */
class Ratings extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 *
	 * @return Ratings the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * Table Name
	 *
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'ratings';
	}
	
	/**
	 * Validation Rules
	 *
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('pnm_id, member_username, rating', 'required'),
			array('pnm_id', 'length', 'max'=>20), 
			array('member_username', 'length', 'max'=>32),
			array('rating', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, pnm_id, member_username, rating, comment', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * Table Relations
	 *
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'pnm' => array(self::BELONGS_TO, 'Pnm', 'pnm_id'),
			'memberUsername' => array(self::BELONGS_TO, 'Users', 'member_username'),
		);
	}
	
	/**
	 * Attribute Labels
	 *
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'pnm_id' => 'Pnm',
			'member_username' => 'Member Username',
			'rating' => 'Rating',
			'comment' => 'Comment',
		);
	}
	
	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * @return CActiveDataProvider the data provider that can
	 * return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.
		
		$criteria=new CDbCriteria;

		$criteria->compare('id', $this->id,true);
		$criteria->compare('pnm_id', $this->pnm_id,true);
		$criteria->compare('member_username', $this->member_username,true);
		$criteria->compare('rating' ,$this->rating,true);
		$criteria->compare('comment', $this->comment,true);

		return new CActiveDataProvider(
			$this, array(
				'criteria'=>$criteria,
			)
		);
	}
}
